package com.scm.servlet.finance;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.scm.model.Somain;
import com.scm.page.Page;
import com.scm.service.SomainService;
/**
 * 收款登记首页
 * @author Surrik_Zhang
 *
 */
@WebServlet("/main/finance/proceedsIndex")
public class ProceedsShowServlet extends HttpServlet{
	private static final long serialVersionUID = 3308689431832035312L;
	private static final Logger LOGGER = Logger.getLogger(ProceedsShowServlet.class);
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
			//获取当前页码参数
			String currentPageStr = req.getParameter("currentPage");
			String payType = req.getParameter("payType");
			if("货到付款".equals(payType)) {
				payType="1";
			}else if("款到发货".equals(payType)) {
				payType="2";
			}else if("预付款到发货".equals(payType)) {
				payType="3";
			}
			//默认当前页码为1
			int currentPage = 1;
			try{
				if(currentPageStr != null && currentPageStr.matches("\\d+")){
					currentPage = Integer.parseInt(currentPageStr);
				}
			}catch(NumberFormatException e){
				//参数不是数字或者为空的时候，默认为第一页
				currentPage = 1;
			}
				
			Map<String,String> queryCondition = new HashMap<String,String>();
			queryCondition.put("type", "1");
			queryCondition.put("payType",payType);
			queryCondition.put("soid", req.getParameter("soId"));
			queryCondition.put("name", req.getParameter("name"));
			queryCondition.put("startDate", req.getParameter("startDate"));
			queryCondition.put("endDate", req.getParameter("endDate"));
			//打印查询条件
			LOGGER.info("[销售单分页查询条件]-->"+queryCondition);
				
			try {
				Page<Somain> page = new SomainService().selectPage(currentPage, queryCondition);
				req.setAttribute("page", page);
					
				req.getRequestDispatcher("/main/finance/proceeds_layer.jsp").forward(req, resp);
			} catch (Exception e) {
				LOGGER.error("收款登记首页异常",e);
			}
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doGet(req, resp);
	}
}
